<?php
global $SSO, $Security, $AppID, $User, $DB;
//Check to see if there is a valid session 
$SessionInfo = $SSO->isValidSession("index.php?action=login", $SSO->getSessionInformation());	
	
//Check to see if the user has rights to be on LivingWeb
$PageRights = array('ADMIN');
$UserRoles = $Security->ValidateUser($SessionInfo['username'], $AppID, $PageRights, 1);

//Grab the user info
$UserInfo = $User->GetUserInfo($SessionInfo['username']);

if(isset($_GET['eventId']) && (isset($_POST['lookupDate']) || isset($_GET['slotDate']))) {
	if(isset($_GET['slotDate'])) {
		$date = strtotime($_GET['slotDate']);	
	}
	else {
		$date = strtotime($_POST['lookupDate']);	
	}
		
	$sql = "select concat(u.firstname,' ',u.lastname) as fullname,
				u.username as username,
				u.email as email,
				case when su.event_id is not null then su.event_id else ss.event_id end as event_id,
				case when su.signup_datetime is not null then su.signup_datetime else ss.slot_datetime end as slot_datetime
				from signups su
				right join signup_slots ss
				on su.signup_datetime = ss.slot_datetime
				left join users u
				on su.username = u.username
				and su.event_id = ss.event_id
				where ss.event_id = " . $_GET['eventId'] . 
				" and month(slot_datetime) = " . date("n",$date) .
				" and day(slot_datetime) = " . date("j",$date) . 
				" and year(slot_datetime) = " . date("Y",$date);
	
	$DB->query($sql);
}
?>
<style>
<!--
.Field
{
	border:1px solid #8d6727;	
}	
.Button
{
	border:1px solid #8d6727;
	background:#e4c894;
}
.TableHeader 
{
 	border-bottom:2px solid #8d6727;
 	font-weight:bold;
}
-->
</style>


<script language="javascript" src="/CommonClientScripts/dcl/choosedate.js"></script>
<link type="text/css" rel="stylesheet" href="/CommonClientScripts/dcl/calendar.css">

<form action="index.php?action=<?php print $_GET['action']; ?>&eventId=<?php print $_GET['eventId'];?>" method="post" name="frmSearhSignup">
<table style="border-left:1px solid #8d6727;border-top:1px solid #8d6727;border-right:3px solid #8d6727;border-bottom:3px solid #8d6727;" cellspacing="0" cellpadding="5">
<tr>
	<td><span class="TB3">Signup Date Search</span></td>
</tr>
<tr>
 <td>
<span class="TB1">Date</span>
<input type="text" id="lookupDate" name="lookupDate" readonly class="Field" value="<?php if(isset($_POST['lookupDate'])) { print $_POST['lookupDate']; } ?>">
&nbsp;
<script language="javascript">
var basicCal = new calendar("FIELD:document.frmSearhSignup.lookupDate;FORMAT:2;DELIMITER:-;");
basicCal.writeCalendar();
</script>&nbsp;&nbsp;&nbsp;&nbsp;
<input name="btnSubmit" value="Submit" type="submit" class="Button">
</td>
</tr>
</table>
</form>
<br><br><br>
<table cellspacing="0" cellpadding="5" width="100%">
	<tr>
		<td class="TableHeader">Full Name</td>
		<td class="TableHeader">Email Address</td>
		<td class="TableHeader">Slot</td>
		<td class="TableHeader">Option</td>
	</tr>
<?php
while($row = $DB->fetch_row()) {
	print '<form action="index.php?action=editSignUpsByEventProcessForm" method="post" name="frmSaveSignup">';
	print "<tr>";
	if($row['fullname'] == "") {
		print '<td style="border-bottom:2px solid #8d6727;"><input name="txtFullName" type="text" class="Field"></td>';
		print '<td style="border-bottom:2px solid #8d6727;"><input name="txtEmail" type="text" class="Field"></td>';
	}
	else {
		print '<td style="border-bottom:2px solid #8d6727;"><input type="text" class="Field" value="'.$row['fullname'].'" readonly></td>';
		print '<td style="border-bottom:2px solid #8d6727;"><input type="text" class="Field" value="'.$row['email'].'" readonly></td>';
	}
	print '<td style="border-bottom:2px solid #8d6727;">' . date('l, F j, Y g:i A', strtotime($row['slot_datetime'])) . "</td>";
	if($row['fullname'] == "") {
		print '<td style="border-bottom:2px solid #8d6727;"><input name="btnSave" type="submit" class="Button" value="Add"></td>';
	}
	else {
		print '<td style="border-bottom:2px solid #8d6727;"><input name="btnSave" type="submit" class="Button" value="Remove"></td>';
	}
	print "</tr>";
	print '<input name="txtSlotDateTime" value="'. $row['slot_datetime'] . '" type="hidden">';
	print '<input name="txtEventId" value="'. $row['event_id'] . '" type="hidden">';
	print '<input name="txtUsername" value="'. $row['username'] . '" type="hidden">';
	print "</form>";
}
?>
</table>